
import { Route, Routes, useLocation, useNavigate, useParams, useSearchParams } from "react-router-dom";
import dayjs from 'dayjs'
import _ from 'lodash'

export const formDate = (data = new Date(), format) => {
    // if (typeof data !== "string") { 
    //     time = new Date().toLocaleString('zh-CN', { hour12: false });
    // }

    if (format == 'MM') {
        return dayjs().month(0) + 1
    }

    if (format == 'DD') {
        return dayjs().date(1)
    }


    return dayjs().format(format)
}


export const clone = function (obj) {
    return _.clone(obj)
}



export const lStorage = {
    setItem(key, value) { localStorage.setItem(key, JSON.stringify(value)) },
    getItem(key, option = { raw: false }) {
        const result = localStorage.getItem(key)
        if (option.raw) { return result } try {
            let res = JSON.parse(result)
            return res
        } catch { return result }
    },
    clear() {
        localStorage.clear()
    }
}




export const CommontHOC = function (ClassCompent) {
    return function HOC(props) {   // 包括2层
        let propsClone = props,
            location = useLocation(),
            navigate = useNavigate(),
            params = useParams(),
            [ups] = useSearchParams()
        return <ClassCompent
            {...propsClone}
            location={location}
            navigate={navigate}
            params={params}
            ups={ups} />
    }
}